package com.biubiushop.exception;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import com.biubiushop.util.ResultData;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

@RestControllerAdvice
public class ServiceExceptionHandler {

    private static final Log log = LogFactory.get();

    @ExceptionHandler(value = ServiceException.class)
    @ResponseBody
    public Object serviceExceptionHandler(ServiceException e) {
        ResultData result = new ResultData(false, e.getCode(), e.getMessage(), null);
        log.error("=====>系统异常:" + e.getMessage(), e);
        return result;
    }

    @ExceptionHandler(value = IllegalOperationException.class)
    @ResponseBody
    public Object illegalOperationExceptionHandler(IllegalOperationException e) {
        ResultData result = new ResultData(false, e.getCode(), e.getMessage(), null);
        log.error("=====>用户非法操作异常:" + e.getMessage(), e);
        return result;
    }

}
